﻿// HSS.Interlink.CustomEvents.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.html)
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2012
// ----------------------------------------------------------------------------
// File:       CustomEvents.cs
// Author:     HSS\gbanta
// Created:    01/17/2012
// Modified:   01/17/2012
// ----------------------------------------------------------------------------
namespace HSS.Interlink
{
	#region Using Directives
	using System;
	using System.ComponentModel;
#if SILVERLIGHT
	using System.Windows.Browser;
#endif
	#endregion

	#region Event Args

	#region UploadFileProgressEventArgs
	/// <summary>
	/// Provides data for the <see cref="UploadClient.UploadProgressChanged"/> event of a <see cref="UploadClient"/>.
	/// </summary>
	public sealed class UploadFileProgressEventArgs : ProgressChangedEventArgs
	{
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="progressPercentage">The percentage of an asynchronous operation that has been completed.</param>
		/// <param name="userToken">The async operation user token.</param>
		/// <param name="bytesSent">The number of bytes sent.</param>
		/// <param name="totalBytesToSend">The total number of bytes to send.</param>
		internal UploadFileProgressEventArgs(int progressPercentage, object userToken, long bytesSent, long totalBytesToSend)
			: base(progressPercentage, userToken)
		{
			this.BytesSent = bytesSent;
			this.TotalBytesToSend = totalBytesToSend;
		}
		/// <summary>
		/// Gets the number of bytes sent.
		/// </summary>
		/// <returns>An System.Int64 value that indicates the number of bytes sent.</returns>
		public long BytesSent { get; private set; }
		/// <summary>
		/// Gets the total number of bytes to send.
		/// </summary>
		/// <returns>An System.Int64 value that indicates the number of bytes that will be sent.</returns>
		public long TotalBytesToSend { get; private set; }
		/// <summary>
		/// Gets the number of bytes remaining.
		/// </summary>
		public long BytesRemaining
		{
			get
			{
				if (!_bytesRemaining.HasValue)
					_bytesRemaining = TotalBytesToSend - BytesSent;
				return _bytesRemaining.Value;
			}
		} long? _bytesRemaining;
	}
	#endregion

	#region UploadFileCompletedEventArgs
	/// <summary>
	/// Provides data for the UploadClient UploadCompleted event.
	/// </summary>
	public sealed class UploadFileCompletedEventArgs : AsyncCompletedEventArgs
	{
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="result">The resulting string from the server.</param>
		/// <param name="exception">The exception if an error was encountered.</param>
		/// <param name="cancelled">true if the upload was cancelled.</param>
		/// <param name="userToken">The user provided token.</param>
		internal UploadFileCompletedEventArgs(string result, Exception exception, bool cancelled, object userToken)
			: base(exception, cancelled, userToken)
		{
			this._result = result;
		}
		/// <summary>
		/// Gets result provided from the upload server.
		/// </summary>
		public string Result
		{
			get
			{
				base.RaiseExceptionIfNecessary();
				return _result;
			}
		} string _result;
	}
	#endregion

	#endregion
}